/************************公告内容制作js*********************************/
define(function(require, exports, module) {
	
	var $ = require("jquery1.7");
	var utils = require("utils");
	var ctx = utils.constants.ctx;
	var Validator = require("validator");
	var ueditor = require("ueditor");
	var noticeBoardService = require("bean/noticeBoardService");
	
	var con_validator = new Validator({
        element: $("#noticeContentForm")
    }).addItem({
        element: '[name=noticeTitle]',
        required: true
    });
	
	$("#sureAddNoticeBtn").bind("click",function(){
		//notice_editor : 前端u_editor创建的对象
		var notice_content = notice_editor.getContent();
		var noticeTitle=$("#noticeTitle").val();
		if(noticeTitle==""){
			alert("请输入标题");
			return;
		}
		
		if(notice_content==""){
			alert("请输入公告内容");
			return;
		}
		var noticePublisher=$("#noticePublisher").val();
		
		var noticeId=$("#noticeId").val();
		// 公告实体
		var notice = {
				title : noticeTitle,
				publisher : noticePublisher,
				content : notice_content
		}
		try{
			if(noticeId==null||""==noticeId){
				noticeBoardService.addNotice(notice);
				alert("添加成功");
				location.href = ctx + "/back/website/noticeManager";
			}else{
				notice["id"]=noticeId;
				noticeBoardService.updateNotice(notice);
				alert("修改成功");
				location.href = ctx + "/back/website/noticeManager";
			}
		}catch(e){
			alert(e.message);
		}
	});
	
	//取消按钮
	$("#cancelAddNoticeBtn").bind("click",function(){
		location.href = ctx + "/back/website/noticeManager";
	});
});